[#import "/framework/JGP.htm"  as JGP]
<!--
项目   parent
作者   LOUFEI [Gavin]
时间   2018/4/12
-->
[@JGP.head "Title"/]
[@JGP.body]
   <jgp-div slot="1-1" _row="['30','90','*']" _runit="px" _aux="true">
       <div slot="1-1">
           <jgp-btn _fn="addUser">新建用户</jgp-btn>
       </div>
       <jgp-query slot="2-1" _target="userGrid" _action="/security/admin/adminApiController/queryUsers">
           <jgp-form-group _title="搜索条件">
               <jgp-text _label="用户名" _name="username"></jgp-text>
           </jgp-form-group>
       </jgp-query>
       <jgp-grid slot="3-1" _id="userGrid" _check="false" _tools_name="true"
                 _record_tools="[{'icon':'drivers-license-o','tip':'设置角色','fn':'editUserRoles'},
                 {'icon':'drivers-license-o','tip':'设置部门','fn':'editUserOrgs'}]">
       </jgp-grid>
   </jgp-div>
[/@JGP.body]

[@JGP.foot]

    <script>
        function addUser(){
            var dialog = {
                'title': '添加用户',
                'width': '400px',
                'height': '300px',
                'url': '/security/admin/adminController/addUser',
                'callback': function (result) {
                    if(result){
                        console.log(result)
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function editUserRoles(data){
            var userId = data.back.record.id;
            var dialog = {
                'title': '设置角色',
                'width': '200px',
                'height': '300px',
                'url': '/security/admin/adminController/chooseRoles/'+userId+'/'+false,
                'callback': function (roles) {
                    if(roles){
                        var ids = [];
                        for(var i=0;i<roles.length;i++){
                            ids.push(roles[i].id);
                        }
                        JGP.$get('/security/admin/adminApiController/changeUserRoles', {
                                    roleIds: ids + '',
                                    userId: userId
                                },
                                function (result) {
                                    JGP.$alert('角色修改成功');
                                }, function () {
                                    JGP.$error('错误');
                                })
                    }
                }
            };
            JGP.$dialog(dialog);
        }

        function editUserOrgs(data){
            var userId = data.back.record.id;
            var dialog = {
                'title': '设置部门',
                'width': '200px',
                'height': '300px',
                'url': '/security/admin/adminController/chooseOrgs/'+userId+'/'+false,
                'callback': function (orgs) {
                    if(orgs){
                        var ids = [];
                        for(var i=0;i<orgs.length;i++){
                            ids.push(orgs[i].id);
                        }
                        JGP.$get('/security/admin/adminApiController/saveUserOrgs', {
                                    orgIds: ids + '',
                                    userId: userId
                                },
                                function (result) {
                                    JGP.$alert('部门设置成功');
                                }, function () {
                                    JGP.$error('错误');
                                })
                    }
                }
            };
            JGP.$dialog(dialog);
        }
    </script>
[/@JGP.foot]